package com.example.myapplication;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.Button;
import android.widget.Toast;

import com.jakewharton.rxbinding2.view.RxView;

import java.util.concurrent.TimeUnit;

public class MainActivity extends AppCompatActivity {
    Button button;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();
        initEvent();
    }

    private void init() {
        button = findViewById(R.id.btn);
    }

    @SuppressLint("CheckResult")
    private void initEvent() {
        //使用RxBinding可做到点击防抖的效果，调用这个方法便可防止短时间内对View的重复点击
        RxView.clicks(button)
                .throttleFirst(5, TimeUnit.SECONDS)
                .subscribe(o -> Toast.makeText(MainActivity.this, "5秒内无法再次点击", Toast.LENGTH_SHORT).show());

    }

}